﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Controls="clr-namespace:Informant.UI.Wpf.Controls"
             xmlns:Converters="clr-namespace:Informant.UI.Wpf.Converters"
             xmlns:ViewModels="clr-namespace:Informant.UI.ViewModels;assembly=Informant.UI.ViewModels"
             xmlns:Utilities="clr-namespace:Informant.UI.Wpf.Utilities"
             xmlns:UI="clr-namespace:Informant.UI;assembly=Informant.UI"
             xmlns:MarkupExtensions="clr-namespace:Informant.UI.Wpf.MarkupExtensions"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="Informant.UI.Wpf.SmsMessagingView"
             d:DesignWidth="517.3"
             d:DesignHeight="493.24">
    <UserControl.Resources>
        <DataTemplate x:Key="SelectableGroupDataTemplate">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected}"
                          Command="{Binding DataContext.ChangeItemIsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                          CommandParameter="{Binding}" />
                <TextBlock Margin="5,0,0,0"
                           Text="{Binding Target.Name}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="SelectableContactDataTemplate">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsSelected}"
                          Command="{Binding DataContext.ChangeItemIsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                          CommandParameter="{Binding}" />
                <TextBlock Margin="5,0,0,0"
                           Text="{Binding Target, Converter={StaticResource ContactNameConverter}}" />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <UserControl.DataContext>
        <ViewModels:SmsMessagingViewModel />
    </UserControl.DataContext>
    <Border Margin="10">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Border Grid.Column="0"
                    Grid.Row="0"
                    Background="#7F000000"
                    BorderBrush="#BF000000"
                    BorderThickness="2"
                    Margin="5,0">
                <Grid>
                    <Grid x:Name="GroupsDisplayPanel"
                          Visibility="{Binding IsLoadingGroups, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <RadioButton x:Name="UseGroups"
                                     Content="Use Groups"
                                     IsChecked="{Binding TargetingContacts, Converter={StaticResource InverseBooleanConverter}}"
                                     GroupName="RecipientsSource"
                                     Foreground="{DynamicResource INFForegroundColor}"
                                     VerticalAlignment="Top"
                                     HorizontalAlignment="Left" />
                        <ComboBox VerticalAlignment="Top"
                                  ItemsSource="{MarkupExtensions:EnumValues {x:Type UI:GroupingMethod}}"
                                  SelectedItem="{Binding GroupingMethod}"
                                  HorizontalAlignment="Right"
                                  MinWidth="80"
                                  Visibility="{Binding TargetingContacts, Converter={StaticResource InverseBooleanToVisibilityConverter}}" />
                        <ScrollViewer Visibility="{Binding TargetingContacts, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
                                      VerticalScrollBarVisibility="Auto"
                                      Grid.Row="1">
                            <ItemsControl x:Name="GroupsSelector"
                                          ItemTemplate="{StaticResource SelectableGroupDataTemplate}"
                                          ItemsSource="{Binding Groups}"
                                          Foreground="{DynamicResource INFForegroundColor}" />
                        </ScrollViewer>
                    </Grid>
                    <DockPanel x:Name="GroupsLoadingPanel"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Visibility="{Binding IsLoadingGroups, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Text="Loading Groups..."
                                   TextWrapping="Wrap"
                                   Foreground="{DynamicResource INFForegroundColor}"
                                   FontWeight="Bold"
                                   FontSize="16" />
                        <Controls:WaitCursor HorizontalAlignment="Center"
                                             VerticalAlignment="Center"
                                             Width="50"
                                             Height="50"
                                             Margin="5,0,0,0"
                                             IsActive="{Binding IsLoadingGroups}" />
                    </DockPanel>
                </Grid>
            </Border>
            <Border Grid.Column="1"
                    Grid.Row="0"
                    Background="#7F000000"
                    BorderBrush="#BF000000"
                    BorderThickness="2"
                    Margin="5,0">
                <Grid>
                    <DockPanel x:Name="ContactsDisplayPanel"
                               Visibility="{Binding IsLoadingContacts, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
                        <RadioButton x:Name="UseContacts"
                                     Content="Use Contacts"
                                     IsChecked="{Binding TargetingContacts}"
                                     GroupName="RecipientsSource"
                                     VerticalAlignment="Top"
                                     Foreground="{DynamicResource INFForegroundColor}"
                                     DockPanel.Dock="Top" />
                        <ScrollViewer Visibility="{Binding TargetingContacts, Converter={StaticResource BooleanToVisibilityConverter}}"
                                      VerticalScrollBarVisibility="Auto"
                                      DockPanel.Dock="Top">
                            <ItemsControl x:Name="ContactsSelector"
                                          ItemTemplate="{StaticResource SelectableContactDataTemplate}"
                                          ItemsSource="{Binding Contacts}"
                                          Foreground="{DynamicResource INFForegroundColor}" />
                        </ScrollViewer>
                    </DockPanel>
                    <DockPanel x:Name="ContactsLoadingPanel"
                               LastChildFill="False"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Visibility="{Binding IsLoadingContacts, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock Text="Loading Contacts..."
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontWeight="Bold"
                                   FontSize="16"
                                   Foreground="{DynamicResource INFForegroundColor}" />
                        <Controls:WaitCursor Width="50"
                                             Height="50"
                                             HorizontalAlignment="Center"
                                             VerticalAlignment="Center"
                                             Margin="5,0,0,0"
                                             IsActive="{Binding IsLoadingContacts}" />
                    </DockPanel>
                </Grid>
            </Border>
            <Border Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Grid.Row="1">
                <DockPanel ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <DockPanel VerticalAlignment="Bottom"
                               DockPanel.Dock="Bottom"
                               Margin="5,5,5,0">
                        <Button x:Name="SendMessageButton"
                                Content="SEND"
                                Command="{Binding SendSms}"
                                VerticalAlignment="Top"
                                Height="35"
                                Width="150"
                                HorizontalAlignment="Right"
                                DockPanel.Dock="Right" />
                        <TextBlock FontSize="16"
                                   Foreground="{DynamicResource INFForegroundDisabledColor}"
                                   VerticalAlignment="Center">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource ValueSlashValueStringConverter}">
                                    <Binding Path="MessageBody.Length" />
                                    <Binding Path="MaxMessageLength" />
                                </MultiBinding>                          
                            </TextBlock.Text></TextBlock>
                    </DockPanel>
                    <TextBox x:Name="MessageContent"
                             TextWrapping="Wrap"
                             AcceptsReturn="True"
                             MaxLength="{Binding MaxMessageLength}"
                             Text="{Binding MessageBody}"
                             Utilities:TextBoxHelper.UpdateBindingOnTextChanged="True"
                             Margin="5,5,5,0"
                             DockPanel.Dock="Bottom" />
                </DockPanel>
            </Border>
            <Border BorderBrush="Black"
                    BorderThickness="1"
                    Background="#BF000000"
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="2"
                    Visibility="{Binding IsSendingSms, Converter={StaticResource BooleanToVisibilityConverter}}">
                <ProgressBar VerticalAlignment="Center"
                             Height="30"
                             Margin="50,0"
                             Maximum="{Binding TotalSms, Mode=OneWay}"
                             Value="{Binding SentSms, Mode=OneWay}" />
            </Border>
        </Grid>
    </Border>
</UserControl>